﻿using System;
using UnityEngine;

namespace Game {
    public class NPCDisplay : Collider {
        public string Name {
            get => mName;
        }
        [SerializeField] private string mName;

        public NPC NPC {
            get;
            private set;
        }
        public NPCTradeComponent TradeComponent {
            get;
            private set;
        }
        
        protected override void Awake() {
            base.Awake();
            NPC = new NPC(this);
            initModules();
        }

        private void initModules() {
            TradeComponent = GetComponent<NPCTradeComponent>();
            if (TradeComponent != null) {
                TradeComponent.Init(this);
                NPC.Add<NPCTradeModule>();
                var tradeModule = NPC.Get<NPCTradeModule>();
                tradeModule.Init(NPC,TradeComponent.Money,TradeComponent.ConfigID);
            }
        }
        
        protected override void onColliderEnter(Collider2D collider) {
            var player = collider.GetComponent<PlayerComponent>();
            if (player != null) {
                TradeComponent.OpenShop();
            }
        }
    }
}